<?
	  layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<div class="col-lg-4">
	<div class="panel" style="height: 490px; overflow: auto;">
		<div class="panel-heading">知识分类管理</div>
		
		<div class="panel-body">
			<div id="ahide" style="margin-top: -10px;margin-left: 10px;">
			<button style="height: 35px;width: 55px;" type="button" class="btn btn-blue btn-xs"onclick="qingling()"><h5>根目录</h5></button></div>
			<ul id="tree" class="ztree" style="width:100%"; overflow:auto;"></ul>
		</div>
	</div>
</div>
<?} ?>
<script type="text/javascript">
	function getQueryString(name) { 
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	var gongYongZiDuanType = window.parent.window[winName].getGongYongZiDuan();
	var inputPId = window.parent.window[winName].getInputPId();
	var inputPName = window.parent.window[winName].getInputPName();
	var getThesauriWordCategoryId = window.parent.window[winName].getThesauriWordCategoryId();
	var classesIds = window.parent.window[winName].getclassesIds();
     	
	//var gongYongZiDuanType = window.parent.getGongYongZiDuan();
	//var inputPId = window.parent.getInputPId();
	//var inputPName = window.parent.getInputPName();
	if(gongYongZiDuanType=="叙词表(主题款目词表)"){
		$("#ahide").hide();
	}else if(gongYongZiDuanType=="叙词表范畴"){
		$("#ahide").show();
	}
	//树状结构
	$(function() {
		initTree();
	});
	var classid="";
	var classname="";
	function initTree(){
		$.ajax({
			type : "post",
			data : {
				"thesauriWordCategoryId":getThesauriWordCategoryId,
				"classesId":classesIds
			},
			url : "./findallThesauriWordCategoryZTree.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}
	var setting;
	if(getThesauriWordCategoryId != 'null'){
		setting = {
			check: {
				enable: true,
				chkboxType: {"Y" : "", "N" : ""},
			},
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			
			callback : {
				onClick : onClick
			},
		};
	
	}else{
		setting = {
			check: {
				enable: false,
				chkboxType: {"Y" : "", "N" : ""},
			},
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			callback : {
				onClick : onClick
			},
		};
	
	}
	
	function drawTree(data) {
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		//zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠
		var nodes = zTree.getNodes();
		for(var i=0;i<data.length;i++){
			if(data[i].page == '0'){
				zTree.checkNode(zTree.getNodeByParam("id",data[i].id), true ); 
			}
		}

	}
	function onClick(e, treeId, treeNode) {
		if(getThesauriWordCategoryId == 'null'){
			classid = treeNode.id;
			classname=treeNode.name;  
		}
	}
	var index = parent.layer.getFrameIndex(window.name);
	function qingling(){
		window.parent.window[winName].$("#"+inputPId).val("0");
		window.parent.window[winName].$("#"+inputPName).val("根节点");
		window.parent.window[winName].layer.tips("Ok", "#xuanze", {time : 5000});
		parent.layer.close(index);
	}
	function queren() {
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var checkedNode = treeObj.getCheckedNodes(); 
		
		for(var i=0;i<checkedNode.length;i++){
			if(checkedNode[i].id!=null){
				/* if(checkedNode[i].children==null){ */
					classid+=checkedNode[i].id+";";
					classname+=checkedNode[i].name+";";
				/* } */
			}
		}
		if (classid == null) {
			window.parent.window[winName].$("#"+inputPId).val("0");
			window.parent.window[winName].$("#"+inputPName).val("根节点");
			parent.layer.close(index);
		} else {
			window.parent.window[winName].$("#"+inputPName).val(classname);
			window.parent.window[winName].$("#"+inputPId).val(classid);
			window.parent.window[winName].layer.tips("Ok", "#xuanze", {
				time : 5000
			});
			parent.layer.close(index);
		}
	}
</script>